#
# @lc app=leetcode.cn id=376 lang=python3
#
# [376] 摆动序列
#
from typing import List


# @lc code=start
class Solution:
    def wiggleMaxLength(self, nums: List[int]) -> int:
        n = len(nums)
        if n <= 1:
            return n

        prediff = nums[1] - nums[0]
        ret = 1 if prediff == 0 else 2
        for i in range(2, n):
            diff = nums[i] - nums[i - 1]
            if prediff * diff < 0 or (diff != 0 and prediff == 0):
                ret += 1
                prediff = diff
            i += 1

        return ret


# @lc code=end
if __name__ == "__main__":
    s = Solution().wiggleMaxLength

    input = [1, 7, 4, 9, 2, 5]
    assert s(input) == 6

    input = [1, 17, 5, 10, 13, 15, 10, 5, 16, 8]
    assert s(input) == 7

    input = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    assert s(input) == 2

    input = [0, 0]
    assert s(input) == 1

    print(1111)
